package linkedList.双指针.剑指;

import linkedList.BaseLinkedListTest;
import po.ListNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 剑指Offer两个链表的第一个公共节点52.java
 * @Description TODO https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/
 * @createTime 2021年03月23日 10:25:00
 */
public class 剑指Offer两个链表的第一个公共节点52 extends BaseLinkedListTest {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        ListNode firstNode = headA, secondNode = headB;
        while (firstNode != secondNode) {
            firstNode = firstNode == null ? headB : firstNode.next;
            secondNode = secondNode == null ? headA : secondNode.next;
        }
        return firstNode;
    }
}
